unit Counts;

interface

uses SysUtils, Data, Inits;

  Function CountVe(CurQ:byte;T,P: double): double;
  Function CountVl(Q,L:byte):double;
  Function Delta(Q,L: byte):double;
  Function GetStab(Q:double):Integer;
  Function Z(T,P: Double):Double;
  Function CountQ(MaxNOser:byte):double;


implementation

Var
  StV: double;
  OldTime: TDateTime;

Function CountQ(MaxNOser:byte):double;
Var
  St: TTimeStamp;
  StopT: TTimeStamp;
  msPassed: Integer;
  V: double;
begin
  if NQoser=0 then
     begin
       oldtime:= Time;
       StV:=  CountVe(State.CurQ, TP.Te, TP.Pe);
     end;
  inc(NQoser);
  if NQoser<MaxNoser then exit;
  NQoser:=0;
  St:= DateTimeToTimeStamp(ot);
  StopT:= DateTimeToTimeStamp(Time);
  V:= CountVe(State.CurQ, TP.Te, TP.Pe);
  msPassed:= StopT.Time - St.Time;
  if (StV<V) then exit
    else result:= 3600*(StV-V)/mspassed;
  oldtime:= Time; StV:= V;
end; {func}

{objem Ve Litrah}
Function CountVe(CurQ:byte;T,P: double): double;
begin
  if CurQ= 3 then result:= (inits.V2_i * P / ((T+Kel) * Z(T,P))) * Tn/Pn
    else  result:= (inits.V1_i * P / ((T+Kel) * Z(T,P))) * Tn/Pn;
end; {proc}

{objem VL Litrah}
Function CountVl(Q,L:byte):double;
begin
  result:= Lich.VL[Q,L] * ( (Lich.PL[Q,L]+Lich.Pbar)/(Lich.TL[Q,L]+Kel) )* Tn/Pn;
end; {proc}


Function Delta(Q,L: byte):double;
begin
  if (Lich.Vzr[Q,1]-Lich.Vzr[Q,2])<>0 then
    result:= (( Lich.VLny[Q,L] - (Lich.Vzr[Q,1]-Lich.Vzr[Q,2])) / (Lich.Vzr[Q,1]-Lich.Vzr[Q,2]) )* 100.0;
end; {func}


Function GetStab(Q:double):Integer;
begin
  result:= TRUNC(Q*60+120);
end;{func}


Function Z(T,P: Double):Double;
Var
  Kx: double;
  f:byte;
begin
   f:= 1;
   T:= T + kel;
   P:= P / 1000;

   if f=1 then
      begin
        Kx:= 0.0; Z:=0.0;
        Kx:= -0.182168 + 0.001125 * T - 0.00000175781*T*T;
        Z:= Kx * P+ 1;
      end; {if f=1}
   if f=2 then
      Z:= 1 - P*(0.126127 - 0.000711 * T + 0.000001*T*T);
{!Z:=1.0;      {    <<<----   !!!!!!!!!!  AZOT   TEST    !!!!!!!}
end; {func}


end.
